<?php

namespace iBrand\Component\Balance\Model;

use Illuminate\Database\Eloquent\Model;

class Balance extends Model
{
    protected $table = 'el_balance';
    protected $guarded = ['id'];

    public function origin()
    {
        return $this->morphTo();
    }

    public function scopeSumBalance($query)
    {
        return $query->sum('value');
    }

    public function scopeSumByUser($query,$userId)
    {
        return $query->where('user_id',$userId)->sum('value');
    }

}
